

package Statistics;


// Referenced classes of package Statistics:
//            Matrix

public class Descriptives
{

    public Descriptives(Matrix A)
    {
        this.A = A;
    }

    public double Max()
    {
        Matrix temp = Sort();
        return temp.myData[A.n - 1][0];
    }

    public double Min()
    {
        Matrix temp = Sort();
        return temp.myData[0][0];
    }

    public double Range()
    {
        return Max() - Min();
    }

    public Matrix Sort()
    {
        Matrix temp = new Matrix(A.myData);
        double d = 0.0D;
        for(int i = 0; i < A.n; i++)
        {
            for(int j = i; j < A.n; j++)
                if(temp.myData[i][0] > temp.myData[j][0])
                {
                    for(int k = 0; k < A.m; k++)
                    {
                        d = temp.myData[i][k];
                        temp.myData[i][k] = temp.myData[j][k];
                        temp.myData[j][k] = d;
                    }

                }

        }

        return temp;
    }

    public Matrix getMean()
    {
        Matrix temp = new Matrix(1, A.m);
        double u = 0.0D;
        for(int j = 0; j < A.m; j++)
        {
            u = 0.0D;
            for(int i = 0; i < A.n; i++)
                u += A.getValue(i, j);

            temp.setValue(0, j, u / (double)A.n);
        }

        return temp;
    }

    public double getMedian()
    {
        Matrix temp = Sort();
        int evenodd = A.n % 2;
        double med = 0.0D;
        if(evenodd == 1)
            med = temp.myData[A.n / 2][0];
        else
            med = (temp.myData[A.n / 2][0] + temp.myData[A.n / 2 + 1][0]) / 2D;
        return med;
    }

    public Matrix getStdDeviation()
    {
        Matrix temp = getVariance();
        Matrix u = new Matrix(1, A.m);
        for(int i = 0; i < A.m; i++)
            u.setValue(0, i, Math.sqrt(temp.myData[0][i]));

        return u;
    }

    public Matrix getVariance()
    {
        Matrix temp = new Matrix(1, A.m);
        double u = 0.0D;
        for(int j = 0; j < A.m; j++)
        {
            u = 0.0D;
            for(int i = 0; i < A.n; i++)
                u += Math.pow(A.getValue(i, j) - getMean().myData[0][j], 2D);

            temp.setValue(0, j, u / (double)A.n);
        }

        return temp;
    }

    public Matrix A;
}